#!/bin/sh

#for periodic run add this script into crontab
# m h  dom mon dow   command
#0 4 * * *  /home/user/bin/epgDownloader.sh

XMLTV_REPO_PATH=/your_local_repo_path
EPGDOWNLOADER_PATH=/you_epgDownloader_directory
SVN_USERNAME=username
SVN_PASSWORD=password

#for the first time for download repository use
#svn checkout https://xmltvdaily.googlecode.com/svn/trunk/ xmltvdaily --username $SVN_USERNAME --password $SVN_PASSWORD

#update local files, other machine may already did new version
svn update $XMLTV_REPO_PATH --username $SVN_USERNAME --password $SVN_PASSWORD

#run epgDownloader
cd $EPGDOWNLOADER_PATH
./epgdownloader.pl
#zip created xmltv.xml
gzip -c xmltv.xml > $XMLTV_REPO_PATH/xmltv.xml.gz

#zip create epg.data
gzip -c epg.data > $XMLTV_REPO_PATH/epg.data.gz

#commit project (fresh program) to svn repository
svn commit $XMLTV_REPO_PATH --username $SVN_USERNAME --password $SVN_PASSWORD --message "`date`"

#update mythtv database 
gunzip -c $XMLTV_REPO_PATH/xmltv.xml.gz > /tmp/xmltv.xml
mythfilldatabase --update -v xmltv --file 1 /tmp/xmltv.xml

